// pages/assetPage/getMoneyCode/getMoneyCode.js
var qrCode = require('../../../utils/bitcoinTool/weapp.qrcode.js')
// console.log(qrCode)
Page({

  /**
   * 页面的初始数据
   */
  data: {
    codeLang:{},
    address:'',
    headerIcon: '',
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //var query = wx.createSelectorQuery().in(this);
    //console.log(query.select('#addressCode'))
    //console.log(options)
    var address = wx.getStorageSync('addressBTC');
    let coinType = wx.getStorageSync('coinType')
    var user = wx.getStorageSync('createUser')
    let addre = coinType.addre || address
    //console.log(coinType.addre)
    qrCode({
      width: 230,
      height: 230,
      canvasId: "myQrcode",
      text: addre
    })
    // var scene = decodeURIComponent(address)
    // console.log(scene)
    this.setData({
      address: addre,
      headerIcon: user && user.head_portrait
    })
  },
  closeCode:function(e){
    wx.navigateBack({
      delta: 2
    })
  },
  getAddress:function(e){
    var add = this.data.address 
    //console.log(wx.T)
    var title = wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'] : wx.T.locales['en']
    //console.log(title)
    wx.setClipboardData({
      data: add,
      success: function (res) {
          //console.log(res);
          if (res.errMsg == 'setClipboardData:ok'){
            wx.showToast({
              title: title.copySuccess,
              icon: 'success',
              duration: 2000
            })
          }
        
        // wx.getClipboardData({
        //   success: function (res) {
        //     //console.log(res.data) // data
        //   }
        // })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      codeLang: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'] : wx.T.locales['en']

    })
    wx.setNavigationBarTitle({
      title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].JLXXPropretyCollectionCode : wx.T.locales['en'].JLXXPropretyCollectionCode
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();  
    //console.log(11)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
  /*shareInfo(){
    wx.showShareMenu({
      withShareTicket: true
    })

  },*/
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res)
      wx.showShareMenu({
        withShareTicket: true,
        success:function(data){
          console.log(data)
        }
      })
      wx.updateShareMenu({
        withShareTicket: true,
        success(data) {
          console.log(data)
        }
      })
      wx.getShareInfo({
        shareTicket:"name",
        timeout:10000,
        success:function(data){
          console.log(data)
        }
      })
    }
    return {
      title: '钱包收款码',
      path: '/pages/assetPage/getMoneyCode/getMoneyCode'
    }
  }
})